/* GUI CONVERTED from bmpsru01.p (converter v1.75) Thu Jun 28 21:18:56 2001 */
/* bmpsru01.p - BILL OF MATERIAL CUMULATIVE LEAD TIME ROLL-UP           */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.9.1.8 $                                                         */
/*V8:ConvertMode=Report                                                 */
/*V8:RunMode=Character,Windows                                          */
/* REVISION: 5.0      LAST EDIT:     05/01/90   BY: emb *B685*          */
/* REVISION: 5.0      LAST EDIT:     07/17/90   BY: emb *B732*          */
/* REVISION: 7.0      LAST MODIFIED: 09/25/91   BY: pma *F003*          */
/* REVISION: 7.0      LAST MODIFIED: 11/20/92   BY: pma *G346*          */
/* REVISION: 7.2      LAST MODIFIED: 12/29/93   BY: ais *FL07*          */
/* REVISION: 8.5      LAST MODIFIED: 10/20/94   BY: mwd *J034*          */
/* REVISION: 8.5      LAST MODIFIED: 11/29/94   BY: tjs *J027*          */
/* REVISION: 7.3      LAST MODIFIED: 02/21/95   BY: cpp *F0JT*          */
/* REVISION: 7.2      LAST MODIFIED: 03/10/95   BY: qzl *F0MC*          */
/* REVISION: 7.2      LAST MODIFIED: 03/14/95   BY: qzl *F0MT*          */
/* REVISION: 8.5      LAST MODIFIED: 08/31/95   BY: srk *J07G*          */
/* REVISION: 8.5      LAST MODIFIED: 09/12/95   BY: tjs *J079*          */
/* REVISION: 8.5      LAST MODIFIED: 07/18/96   BY: ajw *J0Z1*          */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane     */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan    */
/* REVISION: 8.6E     LAST MODIFIED: 06/15/98   BY: *J2N0* Dana Tunstall */
/* REVISION: 8.6E     LAST MODIFIED: 08/13/98   BY: *J2VK* Sandesh Mahagaokar */
/* REVISION: 8.6E     LAST MODIFIED: 12/15/98   BY: *J36F* Sandesh Mahagaokar */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 07/04/00   BY: *N0F3* Rajinder Kamra     */
/* REVISION: 9.1      LAST MODIFIED: 08/11/00   BY: *N0KK* jyn                */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.9.1.8 $    BY: Rajesh Thomas    DATE: 06/28/01 ECO: *M1CD*            */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE bmpsru01_p_1 "As of Date"
/* MaxLen: Comment: */

&SCOPED-DEFINE bmpsru01_p_2 "LL Cum LT"
/* MaxLen: Comment: */

&SCOPED-DEFINE bmpsru01_p_3 "Old Cum LT"
/* MaxLen: Comment: */

&SCOPED-DEFINE bmpsru01_p_5 "Levels"
/* MaxLen: Comment: */

&SCOPED-DEFINE bmpsru01_p_6 "Include Alternate Structures"
/* MaxLen: Comment: */

&SCOPED-DEFINE bmpsru01_p_7 "Cumulative Lead Time"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define new shared variable site like si_site.
define new shared variable bom_code like pt_bom_code.
define new shared variable base_mfg_lead like pt_mfg_lead.
define new shared variable base_cum_lead like pt_cum_lead.

define variable abc   like pt_abc.
define variable abc1  like pt_abc.
define variable part  like pt_part.
define variable part1 like pt_part.
define variable type  like pt_part_type.
define variable type1 like pt_part_type.
define variable line  like pt_prod_line.
define variable line1 like pt_prod_line.

define variable comp like ps_comp.
define variable level as integer.
define variable maxlevel as integer format ">>>" label {&bmpsru01_p_5}.
define variable eff_date as date
   label {&bmpsru01_p_1} initial today.
define variable part_type like pt_part_type.
define variable cum_flag as logical initial yes
   label {&bmpsru01_p_7}.
define variable parent like ps_par.
define variable desc1 like pt_desc1.
define variable um like pt_um.
define variable record as integer extent 100 no-undo.
define variable cum_leadt as integer extent 100 no-undo.

define variable yn like mfc_logical.
define variable work_days as decimal.
define variable i as integer.
define variable cumlead like pt_cum_lead.
define variable inc_alt like mfc_logical
   label {&bmpsru01_p_6}.
define variable pmcode like mfc_logical.
define variable document like mfc_logical no-undo.
define variable l_msg1 as character no-undo format "x(64)".
define variable l_msg2 as character no-undo format "x(64)".

{pxmsg.i
   &MSGNUM = 4114
   &MSGBUFFER = l_msg1
   }
{pxmsg.i
   &MSGNUM = 4115
   &MSGBUFFER = l_msg2
   }

l_msg1 = l_msg1 + " " + l_msg2.

/* SELECT FORM */
/*COLON 32 BELOW WAS PREVIOUSLY COLON 20*/

/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
part     colon 15 part1 label {t001.i} colon 49
   line     colon 15 line1 label {t001.i} colon 49
   type     colon 15 type1 label {t001.i} colon 49
   abc      colon 15 abc1  label {t001.i} colon 49 skip(1)
   site     colon 32
   eff_date colon 32
   inc_alt  colon 32
   skip (1)
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

site = global_site.

/* REPORT BLOCK */
repeat:

   if part1 = hi_char  then part1 = "".
   if line1 = hi_char  then line1 = "".
   if type1 = hi_char  then type1 = "".
   if abc1 = hi_char  then abc1 = "".

   update
      part part1
      line line1
      type type1
      abc abc1
      site
      eff_date
      inc_alt
   with frame a.

   find si_mstr no-lock where si_site = site no-error.
   if not available si_mstr then do:
      next-prompt site with frame a.
      /* SITE DOES NOT EXIST */
      {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}
      undo, retry.
   end.

   if not batchrun then do:
      {gprun.i ""gpsiver.p""
         "(input site, input recid(si_mstr), output return_int)"}
      if return_int = 0 then do:
         /*USER DOES NOT HAVE ACCESS TO THIS SITE */
         {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
         next-prompt site with frame a.
         undo, retry.
      end.
   end.

   /* CREATE BATCH INPUT STRING */
   bcdparm = "".
   {mfquoter.i part   }
   {mfquoter.i part1  }
   {mfquoter.i line   }
   {mfquoter.i line1  }
   {mfquoter.i type   }
   {mfquoter.i type1  }
   {mfquoter.i abc    }
   {mfquoter.i abc1   }
   {mfquoter.i site   }
   {mfquoter.i eff_date}
   {mfquoter.i inc_alt}

   if part1 = "" then part1 = hi_char.
   if line1 = "" then line1 = hi_char.
   if type1 = "" then type1 = hi_char.
   if abc1 = "" then abc1 = hi_char.

   if eff_date = ?
   then do:
      eff_date =  today.
      display eff_date with frame a.
   end. /* IF eff_date ... */

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "printer"
               &printWidth = 132
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "yes"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.

   {mfphead.i}

   FORM /*GUI*/  skip with STREAM-IO /*GUI*/  frame skip_line page-top.
   view frame skip_line.

   work_days = 0.

   /* MAKE SHOP CALENDAR FIND SAME AS IN BILL MATL LEAD TIME REPORT */
   find shop_cal where shop_site = site
      and shop_wkctr = "" and shop_mch = "" no-lock no-error.

   if not available shop_cal then
   find shop_cal where shop_site = ""
      and shop_wkctr = "" and shop_mch = "" no-lock no-error.

   if available shop_cal then do i = 1 to 7:
      if shop_wdays[i] = yes then work_days = work_days + 1.
   end.
   work_days = 7 / work_days.
   if work_days = ? then work_days = 1.

   FORM /*GUI*/  header
      l_msg1
      string(work_days)
   with STREAM-IO /*GUI*/  frame trailer page-bottom width 132.
   view frame trailer.

   /* FIND AND DISPLAY */

   yn = yes.
   repeat:
      if yn then
         find first pt_mstr
         where (pt_part >= part and pt_part <= part1)
         and (pt_prod_line >= line and pt_prod_line <= line1)
         and (pt_part_type >= type and pt_part_type <= type1)
         use-index pt_part no-lock no-error.
      else
         find next pt_mstr
         where (pt_part >= part and pt_part <= part1)
         and (pt_prod_line >= line and pt_prod_line <= line1)
         and (pt_part_type >= type and pt_part_type <= type1)
         use-index pt_part no-lock no-error.
      yn = no.

      if available pt_mstr then do:

         find in_mstr where in_part = pt_part and in_site = site
            no-lock no-error.
         if available in_mstr and (in_abc >= abc and in_abc <= abc1)
            then leave.
         if not available in_mstr
            and (pt_abc >= abc and pt_abc <= abc1)
            then leave.
      end.
      else leave.
      
/*GUI*/ {mfguichk.i  &warn=false} /*Replace mfrpchk*/

   end.

   repeat with frame b width 132 no-attr-space no-box:

      FORM /*GUI*/ 
         pt_part
         pt_desc1
         pt_prod_line
         pt_part_type
         pt_abc
         pt_buyer
         pt_timefence
         cumlead      column-label {&bmpsru01_p_3}
         pt_pm_code
         pt_insp_rqd
         pt_insp_lead
         pt_pur_lead
         pt_mfg_lead
         cum_leadt[1] column-label {&bmpsru01_p_2}
         pt_cum_lead
      with STREAM-IO /*GUI*/  frame b width 152 no-attr-space no-box.

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame b:handle).

      if not available pt_mstr then leave.

      find in_mstr where in_part = pt_part and in_site = pt_site
         no-lock no-error.

      parent = pt_part.
      comp = pt_part.

      find ptp_det no-lock where ptp_part = pt_part
         and ptp_site = site no-error.
      if available ptp_det then do :
         if ptp_bom_code <> "" then comp = ptp_bom_code.
      end.
      else if pt_bom_code <> "" then comp = pt_bom_code.
      assign
         cumlead = 0
         cum_leadt = 0
         maxlevel = 99
         level = 2.

      find first ps_mstr use-index ps_parcomp where ps_par = comp
         and (ps_ps_code <> "A" or inc_alt)
         no-lock no-error.
      loop1:
      repeat:

         if not available ps_mstr
            or level > maxlevel
            or document = yes
         then do:

            document = no.
            repeat:
               level = level - 1.
               if level < 2 then leave.
               find ps_mstr where recid(ps_mstr) = record[level]
                  no-lock no-error.
               if available ps_mstr then do:
                  find pt_mstr no-lock where pt_part = ps_comp
                     no-error.

                  if available pt_mstr then do:

                     find ptp_det no-lock where ptp_part = ps_comp
                        and /*ptp_site = site tony*/ptp_pm_code <>'D' no-error.

                     if cum_flag then do:
                        if available ptp_det then do:
                           if ptp_pm_code <> "P" and ptp_pm_code <> "D"
                           then do:

                              /* EXCLUDE THE LEAD TIME OF A LOCAL PHANTOM    */
                              /* FROM THE CALCULATION. EXCLUDE THE LEAD TIME */
                              /* OF DOCUMENT ITEM FROM CALCULATION           */

                              cumlead = (if (ps_ps_code = "X") or
                                        (ps_ps_code = "D") then
                                           0
                                        else
                                          (ptp_mfg_lead * work_days))
                                           + cum_leadt[level].
                           end.
                           else do:
                              cumlead = (if (ps_ps_code = "D") then
                                         0 else ptp_pur_lead).
                              if ptp_ins_rqd then
                                 cumlead = (if(ps_ps_code = "D") then
                                            0
                                            else
                                               (cumlead + ptp_ins_lead
                                                * work_days)).

                           end.
                        end.
                        else do:
                           if pt_pm_code <> "P"
                              and pt_pm_code <> "D"
                           then do:

                              /* EXCLUDE THE LEAD TIME OF A LOCAL PHANTOM    */
                              /* FROM THE CALCULATION. EXCLUDE THE LEAD TIME */
                              /* OF DOCUMENT ITEM FROM CALCULATION           */

                              cumlead = (if (ps_ps_code = "X") or
                                            (ps_ps_code = "D") then
                                         0
                                         else
                                           (pt_mfg_lead * work_days))
                                            + cum_leadt[level].
                           end.
                           else do:
                              cumlead = (if (ps_ps_code = "D") then
                                         0 else pt_pur_lead).
                              if pt_insp_rqd then
                                 cumlead = (if(ps_ps_code = "D") then
                                            0
                                            else
                                              (cumlead + pt_insp_lead
                                               * work_days)).

                           end.
                        end.

                        /* SAVE LONGEST LEADTIME AT THIS LEVEL */
                        if max(cumlead - ps_lt_off * work_days,0)
                           > cum_leadt[level - 1]
                        then
                           cum_leadt[level - 1]
                              = max(cumlead - ps_lt_off * work_days,0).
                        cum_leadt[level] = 0.
                     end.

                  end.

                  else do:
                     if cum_leadt[level] > cum_leadt[level - 1] then
                        cum_leadt[level - 1] = cum_leadt[level].
                     cum_leadt[level] = 0.
                  end.
               end.
               comp = ps_par.
               find next ps_mstr use-index ps_parcomp
                  where ps_par = comp
                  and (ps_ps_code <> "A" or inc_alt)
                  no-lock no-error.
               if available ps_mstr then leave.
               
/*GUI*/ {mfguichk.i  &warn=false} /*Replace mfrpchk*/

            end.
         end.
         if level < 2 then leave.

         if (eff_date = ? or (eff_date <> ?
            and (ps_start = ? or ps_start <= eff_date)
            and (ps_end = ? or eff_date <= ps_end)))
         then do:

            record[level] = recid(ps_mstr).

            if level < maxlevel or maxlevel = 0 then do:

               if ps_ps_code = "D" then do:
                  assign
                     document = yes
                     level = level + 1.
                  next loop1.
               end. /* IF ps_ps_code */
               else
                  document = no.

               comp = ps_comp.

               find pt_mstr no-lock where pt_part = comp no-error.
               find ptp_det no-lock where ptp_part = comp
                  and ptp_site = site no-error.
               if available ptp_det then do:
                  if ptp_bom_code <> "" then comp = ptp_bom_code.
               end.
               else
               if available pt_mstr and pt_bom_code <> "" then
                  comp = pt_bom_code.

               level = level + 1.
               find first ps_mstr use-index ps_parcomp
                  where ps_par = comp
                  and (ps_ps_code <> "A" or inc_alt)
                  no-lock no-error.
            end.
            else
               find next ps_mstr use-index ps_parcomp
                  where ps_par = comp
                  and (ps_ps_code <> "A" or inc_alt)
                  no-lock no-error.
         end.
         else
            find next ps_mstr use-index ps_parcomp where ps_par = comp
               and (ps_ps_code <> "A" or inc_alt)
               no-lock no-error.
         
/*GUI*/ {mfguichk.i  &warn=false} /*Replace mfrpchk*/

      end.

      find pt_mstr where pt_part = parent no-error.
      if available pt_mstr then do:

         find in_mstr where in_part = pt_part and in_site = pt_site
            no-lock no-error.

         if page-size - line-counter < 2 and pt_desc2 > ""
            then page.

         display
            pt_part pt_desc1
            pt_prod_line
            pt_part_type
            pt_abc when (not available in_mstr)
            in_abc when (available in_mstr) @ pt_abc
         with frame b STREAM-IO /*GUI*/ .

         find ptp_det exclusive-lock where ptp_part = pt_part
            and ptp_site = site no-error.
         if available ptp_det then do:
            /* ADD MFG LT TO CUM LT WHEN NOT A CO-PRODUCT */
            if ptp_joint_type = "" or ptp_joint_type = "5" then do:
               cumlead = ptp_cum_lead.
               if cum_flag then
                  ptp_cum_lead = ptp_mfg_lead * work_days + cum_leadt[1].
               if cum_flag and (ptp_pm_code = "P" or ptp_pm_code = "D")
               then do:
                  ptp_cum_lead = ptp_pur_lead.
                  if ptp_ins_rqd then
                     ptp_cum_lead = ptp_cum_lead + ptp_ins_lead * work_days.
               end.
            end.

            /* COPY BASE PROCESS LEADTIME TO CO-PRODUCT */

            if ptp_joint_type = "1" then do:
               cumlead = ptp_cum_lead.
               bom_code = ptp_bom_code.
               {gprun.i ""bmpsru1a.p""}
               if cum_flag then ptp_mfg_lead = base_mfg_lead.

               if cum_flag then
               assign
                  ptp_mfg_lead = base_mfg_lead
                  ptp_cum_lead = base_cum_lead.
            end.

            if (ptp_pm_code = "P" or ptp_pm_code = "D")
               then pmcode = yes.
            else pmcode = no.
            display
               ptp_buyer @ pt_buyer
               ptp_timefnce @ pt_timefence
               cumlead
               ptp_pm_code @ pt_pm_code
               ptp_ins_rqd  when (pmcode) @ pt_insp_rqd
               ptp_ins_lead when (pmcode) @ pt_insp_lead
               ptp_pur_lead when (pmcode) @ pt_pur_lead
               ptp_mfg_lead when (not pmcode) @ pt_mfg_lead
               cum_leadt[1]
               ptp_cum_lead @ pt_cum_lead
            with frame b STREAM-IO /*GUI*/ .
         end.
         else do: /* NO ptp_det */
            /* ADD MFG LT TO CUM LT WHEN NOT CO-PRODUCT */
            if pt_joint_type = "" or pt_joint_type = "5" then do:
               cumlead = pt_cum_lead.
               if cum_flag then
                  pt_cum_lead = pt_mfg_lead * work_days + cum_leadt[1].
               if cum_flag and caps(pt_pm_code) = "P"
                  or pt_pm_code = "D"
               then do:
                  pt_cum_lead = pt_pur_lead.
                  if pt_insp_rqd then
                     pt_cum_lead = pt_cum_lead + pt_insp_lead * work_days.
               end.
            end.
            /* COPY BASE PROCESS LEADTIME TO CO-PRODUCT */

            if pt_joint_type = "1" then do:
               cumlead = pt_cum_lead.
               bom_code = pt_bom_code.
               {gprun.i ""bmpsru1a.p""}

               if cum_flag then pt_mfg_lead = base_mfg_lead.

               if cum_flag then
               assign
                  pt_mfg_lead = base_mfg_lead
                  pt_cum_lead = base_cum_lead.
            end.
            if (pt_pm_code = "P" or pt_pm_code = "D")
               then pmcode = yes.
            else pmcode = no.
            display
               pt_buyer
               pt_timefence
               cumlead
               pt_pm_code
               pt_insp_rqd  when (pmcode)
               pt_insp_lead when (pmcode)
               pt_pur_lead  when (pmcode)
               pt_mfg_lead  when (not pmcode)
               cum_leadt[1]
               pt_cum_lead
            with frame b STREAM-IO /*GUI*/ .
         end.

         if pt_desc2 > "" then do
            with frame b:
            down 1.
            display pt_desc2 @ pt_desc1 WITH STREAM-IO /*GUI*/ .
         end.
      end.

      repeat:
         find next pt_mstr where (pt_part >= part and pt_part <= part1)
            and (pt_prod_line >= line and pt_prod_line <= line1)
            and (pt_part_type >= type and pt_part_type <= type1)
            use-index pt_part no-lock no-error.

         if available pt_mstr then do:
            find in_mstr where in_part = pt_part and in_site = pt_site
               no-lock no-error.
            if available in_mstr and (in_abc >= abc and in_abc <= abc1)
               then leave.
            if not available in_mstr
               and (pt_abc >= abc and pt_abc <= abc1)
               then leave.
         end.
         else leave.
         
/*GUI*/ {mfguichk.i  &warn=false} /*Replace mfrpchk*/

      end.
      
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


   end.

   /* REPORT TRAILER */
   {mfrtrail.i}

   hide frame trailer.

end.
